import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
// ElementPlus 相关库的导入
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// 导入icon图标库
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// 导入暗黑模式主题，在index.html文件中：需在 html 上添加一个名为 dark 的类
import 'element-plus/theme-chalk/dark/css-vars.css'
import './assets/font/iconfont.css'
import '@/assets/css/index.css'
import store from './store';
import {createPinia} from "pinia";

// 创建一个应用
const app = createApp(App)
// 注册elementplus
app.use(ElementPlus, {

    locale: zhCn,
})
// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// 注册路由后挂载
app.use(router).mount('#app')

// createApp(App).use(store).mount('#app');

const pinia = createPinia()
app.use(pinia)

//解决前端报错问题
const debounce = (fn, delay) => {
    let timer
    return (...args) => {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            fn(...args)
        }, delay)
    }
}

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
    constructor(callback) {
        callback = debounce(callback, 200);
        super(callback);
    }
}